home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / BC_TI.ARJ / TI649.ASC < prev    next >
Text File  |  1992-02-25  |  14KB  |  463 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  649
  9.   VERSION  :  2.0
  10.        OS  :  PC DOS
  11.      DATE  :  February 25, 1992                        PAGE  :  1/7
  12.  
  13.     TITLE  :  Common Causes of General Protection Faults
  14.  
  15.  
  16.  
  17.  
  18.   WHAT? GENERAL PROTECTION ERROR!
  19.  
  20.   Protected mode development tools permit much  larger  programs to
  21.   be  compiled  faster  than their real mode  counterparts.    They
  22.   accomplish this by allowing  the  use  of  a vastly larger memory
  23.   area  than  is  available to real mode tools. There is a cost for
  24.   this  increased  capability,  however; many of us  will  have  to
  25.   change the coding practices and strategies we grew  to  depend on
  26.   with the relatively tolerant real mode development tools.
  27.  
  28.   Central to this change  is  the  increasingly  notorious "General
  29.   Protection Fault."   A  GP  Fault  is generated by what one might
  30.   think of as a debugger built into the CPU and is enabled any time
  31.   a program is operating in protected mode.  This debugger-in-a-CPU
  32.   is very, very uncompromising  with  regard  to  the rules which a
  33.   program  must  obey  while  availing  itself  of  protected  mode
  34.   capabilities.
  35.  
  36.   For  example, suppose a block of memory  is  allocated  for  use.
  37.   Further suppose that we code an errant read or write outside this
  38.   block.  In real mode this  may  show  up in a variety of more-or-
  39.   less unacceptable ways; many of these we can choose to ignore.
  40.  
  41.   The  same  program  executed  in  protected  mode  will,  in  all
  42.   probably, display a General Protection  Fault  error  message and
  43.   immediately exit to DOS.   This illustrates the cost of operating
  44.   in  protected  mode;  our  right  to  ignore  coding problems  is
  45.   seriously limited.
  46.  
  47.   There is an upside to this, however: any program  that  runs  for
  48.   any length of time in protected mode is likely to be far more bug
  49.   free than an equivalent program executed only in real mode.
  50.  
  51.   General Protection Faults are generated,  however,  by  more than
  52.   just reads or writes outside proper memory areas.
  53.  
  54.   The following list, extracted  from  the  Intel  386 Programmer's
  55.   Reference Manual, serves to  suggest  the  level  of "protection"
  56.   which we may expect while operating in protected mode:
  57.  
  58.   -----------------------------------------------------------------------
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                            NUMBER  :  649
  75.   VERSION  :  2.0
  76.        OS  :  PC DOS
  77.      DATE  :  February 25, 1992                        PAGE  :  2/7
  78.  
  79.     TITLE  :  Common Causes of General Protection Faults
  80.  
  81.  
  82.  
  83.  
  84.   All protection violations which do  not  cause  another exception
  85.   cause  a General-Protection Fault.  This  includes  (but  is  not
  86.   limited to):
  87.  
  88.   a.  Exceeding the segment limit when using CS, DS, ES, FS, or GS
  89.       segments
  90.  
  91.   b.  Exceeding the segment limit when referencing a descriptor
  92.       table
  93.  
  94.   c.  Transferring execution to a segment which is not executable
  95.  
  96.   d.  Writing to a read-only data segment or a code segment
  97.  
  98.   e.  Reading from an execute-only code segment
  99.  
  100.   f.  Loading the SS register with a selector for a read-only
  101.       segment (unless the  selector comes from a TSS during a  task
  102.       switch, in which case an invalid-TSS exception occurs)
  103.  
  104.   g.  Loading the SS, DS, ES, FS, or GS register with a selector
  105.       for a system segment
  106.  
  107.   h.  Loading the DS, ES, FS, or GS register with a selector for an
  108.       execute-only code segment
  109.  
  110.   i.  Loading the SS register with the selector of an executable
  111.       segment
  112.  
  113.   j.  Accessing memory using the DS, ES, FS, or GS register when it
  114.       contains a null selector
  115.  
  116.   k.  Switching to a busy task
  117.  
  118.   l.  Violating privilege rules
  119.  
  120.   m.  Exceeding the instruction length limit of 15 bytes (this only
  121.       can occur when redundant prefixes are placed before an
  122.       instruction)
  123.  
  124.   n.  Loading the CRO register with a set PG bit (paging enabled)
  125.       and a clear PE bit (protection disabled)
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                            NUMBER  :  649
  141.   VERSION  :  2.0
  142.        OS  :  PC DOS
  143.      DATE  :  February 25, 1992                        PAGE  :  3/7
  144.  
  145.     TITLE  :  Common Causes of General Protection Faults
  146.  
  147.  
  148.  
  149.  
  150.   o.  Interrupt or exception through an interrupt or trap gate from
  151.       virtual-8086 mode to a handler at a privilege level other
  152.       than 0
  153.  
  154.   p.  The general-protection exception is a fault. In response to a
  155.       general-protection exception, the processor pushes an error
  156.       code onto the exception handler's stack.  If loading a
  157.       descriptor causes the exception, the error code contains a
  158.       selector to the descriptor; otherwise, the error code is
  159.       null.  The source of the selector in an error code may be any
  160.       of the following:
  161.  
  162.      1.  An operand of the instruction
  163.  
  164.      2.  A  selector  from  a gate which  is  the  operand  of  the
  165.          instruction
  166.  
  167.      3.  A selector from a TSS involved in a task switch
  168.  
  169.    -----------------------------------------------------------------------
  170.  
  171.   PROGRAM OR DEVELOPMENT TOOL?
  172.  
  173.   Obviously  if your applications are going to  be  subject  to  GP
  174.   Fault  errors  it  stands to reason that  the  development  tools
  175.   themselves must abide by  the  same rules and are subject to this
  176.   demanding debugger-in-a-CPU.
  177.  
  178.   It  is  unlikely  that any significant program has ever been bug-
  179.   free  and  Borland's  development tools are no different.  As you
  180.   might expect, we are dedicated to eliminating any  bugs  that can
  181.   be identified. One might guess that this would be an easy task.
  182.  
  183.   Unfortunately  the protected mode mechanism does not  distinguish
  184.   between problems in the code  being developed under the tools and
  185.   problems with the tools  themselves.    Consequently,  it becomes
  186.   necessary for the developer  to  take  additional steps to assure
  187.   that their code is not the cause.  Although there is  little that
  188.   Borland can do  to  make  this  process easier, we can supply you
  189.   with a list  of  known  problems  in the BC++ tools that generate
  190.   reproducible  GP Fault errors.  If you find  a  problem  you  are
  191.   encountering on this list you can eliminate your  program  as the
  192.   culprit.
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                            NUMBER  :  649
  207.   VERSION  :  2.0
  208.        OS  :  PC DOS
  209.      DATE  :  February 25, 1992                        PAGE  :  4/7
  210.  
  211.     TITLE  :  Common Causes of General Protection Faults
  212.  
  213.  
  214.  
  215.  
  216.       -  Moving  the  mouse  while  BCX  is setting up to run  your
  217.          program  can cause a GP Fault.  This  can  happen  if  the
  218.          mouse  is  moving  when  BCX  switches  from  compiling to
  219.          linking also but  not  nearly as often as choosing RUN|RUN
  220.          and moving the mouse after the link or dependency check.
  221.  
  222.       -  Window Resize/Move-  Clicking  the  mouse  almost anywhere
  223.          outside  of a BCX window set up  for  resizing  or  moving
  224.          (green bordered)
  225.  
  226.       -  Using the ,m (memory dump) option in a BCX watch window
  227.  
  228.       -  Doing  a  Repaint  Desktop  in  BCX with a  HERCULES  card
  229.          attached (and any video cards doing Hercules simulation)
  230.  
  231.       -  Compiling a program under BCX using  the  ternary operator
  232.          with the second or third variables undefined
  233.  
  234.       -  Compiling a program with the OPTIONS|DIRECTORY|INCLUDE box
  235.          filled to its maximum
  236.  
  237.       -  Inspecting  on a static member of a  class  with  the  BCX
  238.          debugger
  239.  
  240.       -  Compiling  the  DLLDEMO  examples  program under BCX using
  241.          different segment names for BSS or DATA
  242.  
  243.   Ok, so the problem can't be in your application because  you have
  244.   reduced it to the point where all it does is print "Hello, world"
  245.   and it's still giving you a GP Fault; and it's not on the list of
  246.   known problems.
  247.  
  248.   There are two final sources  of  General  Protection  Faults that
  249.   have little to do with either the tools or the  application under
  250.   development;    the    Operating    System   configuration,   the
  251.   configuration of the  hardware  and,  on  occasion,  the hardware
  252.   itself.
  253.  
  254.  
  255.   OPERATING SYSTEM CONFIGURATION?
  256.  
  257.   GP Faults generated by OS configuration are not  uncommon.   Most
  258.   of  them find their cause in the  variety  of  memory  management
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Borland C++                            NUMBER  :  649
  273.   VERSION  :  2.0
  274.        OS  :  PC DOS
  275.      DATE  :  February 25, 1992                        PAGE  :  5/7
  276.  
  277.     TITLE  :  Common Causes of General Protection Faults
  278.  
  279.  
  280.  
  281.  
  282.   standards (or lack thereof) which  characterize  use  of extended
  283.   and expanded (EMS) memory.
  284.  
  285.   Since the advent of  the  IBM PC the industry has progressed from
  286.   the total absence of a standard, as exemplified  by  IBM's VDISK,
  287.   through VCPI to today's most likely candidate, the DPMI standard.
  288.   However, even DPMI remains unfinished at revision 0.9.
  289.  
  290.   As you might guess, writing  a  development  tool  or application
  291.   which will not clash with any potential user of  memory  is  very
  292.   difficult, if not impossible, to do without  an industry-accepted
  293.   memory standard.
  294.  
  295.   To resolve these inevitable incompatibilities, the user is at the
  296.   mercy  of  the  contending  utilities.  If they can  be  manually
  297.   configured  to  avoid  conflict,  the  problem  can  be resolved;
  298.   otherwise, the user must assure they they are never loaded at the
  299.   same time.  Many modern utilities (e.g., QEMM  &  MAX386) provide
  300.   the options necessary  to  resolve  such  contentiousness.   Many
  301.   older utilities (e.g., VDISK) do not.
  302.  
  303.   To  quickly  eliminate  OS  configuration (device drivers, TSR's,
  304.   etc.) as a source of difficulty, simply boot your computer from a
  305.   vanilla DOS disk.  If a vanilla DOS disk isn't  available, rename
  306.   your system's  CONFIG.SYS  and  AUTOEXEC.BAT  to  something  else
  307.   (e.g.,  CONFIG.TMP  and  AUTOEXEC.TMP)  and reboot your computer.
  308.   Note that  "vanilla" means without any drivers or TSR's INCLUDING
  309.   the mouse driver.  For some of us, running for any length of time
  310.   without a mouse is excruciating; you will simply have to grin and
  311.   bear it for a short time.
  312.  
  313.   Now execute  the  offending  process;  if  the  problem persists,
  314.   contact   Borland  Technical  Support  (see  final  section   for
  315.   procedures).    If  the problem seems to  have  been  eliminated,
  316.   however,  you  will   need   to  begin  the  tedious  but  rather
  317.   undemanding  process  of  identifying  the  offending  driver/TSR
  318.   through   stepwise   restoration   of   your   normal   operating
  319.   configuration.
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.   PRODUCT  :  Borland C++                            NUMBER  :  649
  339.   VERSION  :  2.0
  340.        OS  :  PC DOS
  341.      DATE  :  February 25, 1992                        PAGE  :  6/7
  342.  
  343.     TITLE  :  Common Causes of General Protection Faults
  344.  
  345.  
  346.  
  347.  
  348.   HARDWARE DEPENDENCIES?
  349.  
  350.   Finally,  there  are  some  GP  Fault  problems  which cannot  be
  351.   resolved  without  replacing  the computer or some  part  of  the
  352.   computer.  Often the problem revolves around the  system  BIOS or
  353.   some unique aspect of the computer's architecture.
  354.  
  355.   For instance, a problem that occurs often enough to be well known
  356.   involves GP  Faults generated when the UPARROW and DOWNARROW keys
  357.   are  pressed  with  NUM  LOCK  enabled.  For some computers,  the
  358.   manufacturer provides a ROM BIOS update which solves the problem.
  359.  
  360.   In  addition,  any  80x286  based  computer is more likely to  be
  361.   affected by GP Fault errors in protected mode than are  80x386 or
  362.   80x486 computers.  This is largely due to the  speed  with  which
  363.   these computers  can switch between protected mode and real mode.
  364.   For  instance,  use  of  a  mouse  in  protected mode  represents
  365.   hundreds of protected/real mode exchanges per second; any failure
  366.   on  the  part  of  the  hardware  to  realize  this  demand  will
  367.   inevitably result in a GP Fault error.
  368.  
  369.   Identification of this type of problem  usually  requires running
  370.   the failing  installation  on  a  different  computer,  trying to
  371.   change as little as possible.  Although such "in vivo" testing is
  372.   unlikely  to  be  absolutely conclusive, it will often serve as a
  373.   tiebreaker for a final decision.
  374.  
  375.  
  376.   REPORTING A GENERAL PROTECTION FAULT PROBLEM
  377.  
  378.   Assuming that the problem is independent of the  program  you are
  379.   developing, occurs under a  vanilla  operating  system as well as
  380.   under your normal operating  system  configuration  and is not on
  381.   the  list  of known GP fault problems,  it  is  time  to  contact
  382.   Borland  Technical  Support.    When contacting Technical Support
  383.   regarding a GP Fault, it will  be  most efficient if you have the
  384.   following information available:
  385.  
  386.      1.  A set of steps to  reproduce  the  problem  (including any
  387.          code that may be required)
  388.  
  389.      2.  A description of the problem
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.   PRODUCT  :  Borland C++                            NUMBER  :  649
  405.   VERSION  :  2.0
  406.        OS  :  PC DOS
  407.      DATE  :  February 25, 1992                        PAGE  :  7/7
  408.  
  409.     TITLE  :  Common Causes of General Protection Faults
  410.  
  411.  
  412.  
  413.  
  414.      3.  The GP information  which  was displayed just prior to the
  415.          exit to DOS.  It looks like:
  416.  
  417.                             GP at 0020 0FC8
  418.  
  419.          The following information may  also  be  requested  by the
  420.          Technical Support Engineer, depending on the problem:
  421.  
  422.      4.  BIOS date, manufacturer and revision
  423.  
  424.      5.  Computer make and model
  425.  
  426.      6.  Memory configuration
  427.  
  428.      7.  Operating system revision
  429.  
  430.      8.  Graphics adapter make, model and Video BIOS revision/date
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.